import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';

//element UI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);
// 引入自定义图标
import "@/assets/iconfont/iconfont.css";

// 让低版本浏览器支持promise的finally方法
import promiseFinally from 'promise.prototype.finally';
promiseFinally.shim();

// 引入iView
import "view-design/dist/styles/iview.css";
import iView from "view-design";
Vue.use(iView);

// 引入组件
import zmtt from 'zmtt-vue-lib/lib/pc/index';
import "zmtt-vue-lib/lib/pc/styles/reset.css";
Vue.use(zmtt);


// 引入工具类
import util from "zmtt-vue-lib/lib";
Vue.use(util);

// 配置跳转登录
zmtt.apiConfig.jumpLogin = ()=>{
  if(router.currentRoute.name !== "Login"){
    // 移除token并跳转到登录页
    store.dispatch("resetState");
    window.storage.removeItem(window.storage.key.token);
    router.push({name: "Login"});
  }
};

// 配置请求拦截器
zmtt.apiConfig.interceptorsRequest = (config) => {
  if(window.storage.getItem(window.storage.key.token)){
    config.headers = {
      'token': window.storage.getItem(window.storage.key.token),
      "Content-Type":'application/json',
    };
  }else{
    config.headers = {
      "Content-Type":'application/json',
    };
  }
  return config;
};

// 加入0为成功请求标识
zmtt.apiConfig.requestSuccessCode.push(0);

Vue.config.productionTip = false;

// 监听窗口改变
window.utils.rem.setHtmlFontSize();
window.addEventListener('resize', window.utils.rem.debounce(window.utils.rem.setHtmlFontSize), false);

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app');
